﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agresso.Interface.Layer.Gateway;
using Agresso.Interface.Layer.Domain;
using System.Data.SqlClient;
using Agresso.Interface.Layer.SQL;
using System.Data;

namespace Agresso.Interface.Layer.Service
{
    public class ud_algbatchinput_textService
    {
        DataBaseConnectivity m_dataBaseConectivity;
        public ud_algbatchinput_textService()
        {
            m_dataBaseConectivity = new DataBaseConnectivity();
        }
        public void Insert(string client, string batch_id, long order_id, string ext_ord_ref, int text_line_no, string po_notes_text)
        {
            try
            {
                ud_algbatchinput_text abi = new ud_algbatchinput_text();
                abi.client = client;
                abi.batch_id = batch_id;
                abi.order_id = order_id;
                abi.ext_ord_ref = ext_ord_ref;
                abi.text_line_no = text_line_no;
                abi.po_notes_text = po_notes_text;
                m_dataBaseConectivity.AgrTempConnectionSQLConnection.Open();
                SqlCommand cmd = new SqlCommand(ud_algbatchinput_textSQL.Insert(), m_dataBaseConectivity.AgrTempConnectionSQLConnection);
                cmd.Parameters.Add("@client", SqlDbType.VarChar).Value = abi.client.Length > 25 ? abi.client.Substring(0, 25) : abi.client;
                cmd.Parameters.Add("@batch_id", SqlDbType.VarChar).Value = abi.batch_id.Length > 25 ? abi.batch_id.Substring(0, 25) : abi.batch_id;
                cmd.Parameters.Add("@order_id", SqlDbType.BigInt).Value = abi.order_id;
                cmd.Parameters.Add("@ext_ord_ref", SqlDbType.VarChar).Value = abi.ext_ord_ref.Length > 100 ? abi.ext_ord_ref.Substring(0, 100) : abi.ext_ord_ref;
                cmd.Parameters.Add("@text_line_no", SqlDbType.Int).Value = abi.text_line_no;
                cmd.Parameters.Add("@PO_notes_text", SqlDbType.VarChar).Value = abi.po_notes_text.Length > 60 ? abi.po_notes_text.Substring(0, 60) : abi.po_notes_text;
                cmd.Parameters.Add("@order_id_assigned", SqlDbType.BigInt).Value = abi.order_id_assigned;
                cmd.Parameters.Add("@processed_date", SqlDbType.DateTime).Value = abi.processed_date;
                cmd.ExecuteNonQuery();
            }
            catch (Exception x)
            {
                LogService.WriteLogException(x);
                throw x;
            }
            finally
            {
                m_dataBaseConectivity.AgrTempConnectionSQLConnection.Close();
            }
        }
        public void Insert(ud_algbatchinput_text abi)
        {
            try
            {
                m_dataBaseConectivity.AgrTempConnectionSQLConnection.Open();
                SqlCommand cmd = new SqlCommand(ud_algbatchinput_textSQL.Insert(), m_dataBaseConectivity.AgrTempConnectionSQLConnection);
                cmd.Parameters.Add("@client", SqlDbType.VarChar).Value = abi.client.Length > 25 ? abi.client.Substring(0, 25) : abi.client;
                cmd.Parameters.Add("@batch_id", SqlDbType.VarChar).Value = abi.batch_id.Length > 25 ? abi.batch_id.Substring(0, 25) : abi.batch_id;
                cmd.Parameters.Add("@order_id", SqlDbType.BigInt).Value = abi.order_id;
                cmd.Parameters.Add("@ext_ord_ref", SqlDbType.VarChar).Value = abi.ext_ord_ref.Length > 100 ? abi.ext_ord_ref.Substring(0, 100) : abi.ext_ord_ref;
                cmd.Parameters.Add("@text_line_no", SqlDbType.Int).Value = abi.text_line_no;
                cmd.Parameters.Add("@PO_notes_text", SqlDbType.VarChar).Value = abi.po_notes_text.Length > 60 ? abi.po_notes_text.Substring(0, 60) : abi.po_notes_text;
                cmd.Parameters.Add("@order_id_assigned", SqlDbType.BigInt).Value = abi.order_id_assigned;
                cmd.Parameters.Add("@processed_date", SqlDbType.DateTime).Value = abi.processed_date;
                cmd.ExecuteNonQuery();
            }
            catch (Exception x)
            {
                LogService.WriteLogException(x);
                throw x;
            }
            finally
            {
                m_dataBaseConectivity.AgrTempConnectionSQLConnection.Close();
            }
        }
    }
}
